package com.dm0858.bianmin.mine.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebViewClient;

import com.alibaba.fastjson.JSON;
import com.dm0858.bianmin.R;
import com.dm0858.bianmin.databinding.ActivityPlatformConstructionLayoutBinding;
import com.dm0858.bianmin.mine.base.BaseActivity;
import com.dm0858.bianmin.mine.bean.PlatformConstructionBeanData;
import com.dm0858.bianmin.mine.listener.IResultListener;
import com.dm0858.bianmin.mine.model.MineModel;
import com.dm0858.bianmin.mine.network.Retrofit;
import com.dm0858.bianmin.mine.tools.LogUtils;

/**
 * @description 平台建设
 * @author 迪迪丶Sir
 * @e-mail asd969709719@qq.com
 * @since 2020-05-02
 **/
public class PlatformConstructionActivity extends BaseActivity implements View.OnClickListener{

    private ActivityPlatformConstructionLayoutBinding binding;

    private Retrofit retrofit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this,R.layout.activity_platform_construction_layout);
        binding.setOnClick(this);
        initData();
    }

    @Override
    protected void initData() {
        if (retrofit == null) retrofit = new Retrofit();
        MineModel.sysUpdateTxt(retrofit,object -> {
            PlatformConstructionBeanData data = JSON.parseObject(object.toString(),PlatformConstructionBeanData.class);
            WebSettings webSettings = binding.webView.getSettings();
            //允许使用js
            webSettings.setJavaScriptEnabled(true);
            //不支持屏幕缩放
            webSettings.setSupportZoom(false);
            webSettings.setBuiltInZoomControls(false);
            //不显示webview缩放按钮
            webSettings.setDisplayZoomControls(false);
            binding.webView.setWebViewClient(new WebViewClient());
            binding.webView.loadDataWithBaseURL(null,data.getContent(), "text/html" , "utf-8", null);
        });
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                onBackPressed();
                break;
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && binding.webView.canGoBack()) {
            binding.webView.goBack();// 返回前一个页面
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}